package com.tarena.spring.test.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class OSCondtion implements Condition {
    /**
     * 条件判断执行的逻辑 matches的返回值 控制了条件是否满足
     * return  true 表示条件满足 该加载就加载 false表示条件不满足,不会加载配置逻辑
     */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment environment = context.getEnvironment();
        String property = environment.getProperty("os.name");
        System.out.println("当前操作系统的名字"+property);
        if (property.contains("Windows")){
            //条件满足
            return true;
        }
        //条件不满足
        return false;
    }
}
